
static inline enum hrtimer_restart hrtimer_dummy_timeout(struct hrtimer *unused)
{
    return HRTIMER_NORESTART;
}

static inline int hrtimer_clockid_to_base(clockid_t clock_id)
{
    switch (clock_id)
    {
    case CLOCK_REALTIME:
        return HRTIMER_BASE_REALTIME;
    case CLOCK_MONOTONIC:
        return HRTIMER_BASE_MONOTONIC;
    case CLOCK_BOOTTIME:
        return HRTIMER_BASE_BOOTTIME;
    case CLOCK_TAI:
        return HRTIMER_BASE_TAI;
    default:
        return HRTIMER_BASE_MONOTONIC;
    }
}

static void __hrtimer_setup(struct hrtimer *timer,
                            enum hrtimer_restart (*function)(struct hrtimer *),
                            clockid_t clock_id, enum hrtimer_mode mode)
{
    bool softtimer = !!(mode & HRTIMER_MODE_SOFT);
    struct hrtimer_cpu_base *cpu_base;
    int base;

    /*
     * On PREEMPT_RT enabled kernels hrtimers which are not explicitly
     * marked for hard interrupt expiry mode are moved into soft
     * interrupt context for latency reasons and because the callbacks
     * can invoke functions which might sleep on RT, e.g. spin_lock().
     */
    if (!(mode & HRTIMER_MODE_HARD))
        softtimer = true;

    memset(timer, 0, sizeof(struct hrtimer));

    cpu_base = raw_cpu_ptr(&hrtimer_bases);

    /*
     * POSIX magic: Relative CLOCK_REALTIME timers are not affected by
     * clock modifications, so they needs to become CLOCK_MONOTONIC to
     * ensure POSIX compliance.
     */
    if (clock_id == CLOCK_REALTIME && mode & HRTIMER_MODE_REL)
        clock_id = CLOCK_MONOTONIC;

    base = softtimer ? HRTIMER_MAX_CLOCK_BASES / 2 : 0;
    base += hrtimer_clockid_to_base(clock_id);
    timer->is_soft = softtimer;
    timer->is_hard = !!(mode & HRTIMER_MODE_HARD);
    timer->base = &cpu_base->clock_base[base];
    timerqueue_init(&timer->node);

    if (WARN_ON_ONCE(!function))
        ACCESS_PRIVATE(timer, function) = hrtimer_dummy_timeout;
    else
        ACCESS_PRIVATE(timer, function) = function;
}
